#include "InetAddress.hpp"

namespace xww
{  

InetAddress::InetAddress(unsigned short port, const string& ip)
{
    memset(&_addr, 0, sizeof(_addr));
    _addr.sin_family = AF_INET;
    _addr.sin_port = htons(port);
    _addr.sin_addr.s_addr = inet_addr(ip.c_str());

}

string InetAddress::ip() const
{
    return string(inet_ntoa(_addr.sin_addr));//inet_ntoa将网络字节序的IP地址转换为点分十进制字符串
}

unsigned short InetAddress::port() const
{
    return ntohs(_addr.sin_port); //ntohs将网络字节序的端口号转换为主机字节序       
} 

}//endl of namespace xww